package ad_exercise_3.model;

import java.util.Random;

/**
 * Custom stack implementation. Contains methods for adding new elements to the front or the back of the list. Also contains a method for adding new elements to a random position in the list or taking an element from the front of the list.
 * 
 * @author Pieter Koopman (number?)
 * @author Karen Berntsen (s0815799)
 * @author Erik Stens (s0615374)
 */
public class CustomStack<E> extends CustomList<E> {
	private static final Random	random	= new Random();
	
	public CustomStack() {
		super();
	}
	
	/**
	 * Adds a new element to the front of the list
	 * 
	 * @param e
	 *            the element to add
	 */
	public void addToFront(E e) {
		add(0, e);
	}
	
	/**
	 * Adds a new element to the back of the list
	 * 
	 * @param e
	 *            the element to add
	 */
	public void addToBack(E e) {
		add(e);
	}
	
	/**
	 * Adds a new element at a (pseudo) random position in the list
	 * 
	 * @param e
	 *            the element to add
	 */
	public void addSomewhere(E e) {
		add(random.nextInt(size() + 1), e);
	}
	
	/**
	 * Takes the first element out of the list and returns it
	 * 
	 * @return the first element of the list
	 * 
	 * @throws java.lang.RuntimeException
	 *             if the list is empty
	 */
	public E takeFirst() throws RuntimeException {
		if (isEmpty()) {
			throw new RuntimeException("Can't remove a card from an empty list!");
		}
		
		return remove(0);
	}
}